import { createI18n } from 'vue-i18n/dist/vue-i18n.cjs'
import zh from '../locales/zh'
import en from '../locales/en'
import ru from '../locales/ru'

// 获取用户之前选择的语言或浏览器语言
const getUserLanguage = () => {
  // 检查是否在客户端环境
  if (typeof window !== 'undefined' && window?.localStorage) {
    const savedLanguage = localStorage.getItem('userLanguage')
    if (savedLanguage) return savedLanguage
    
    const browserLang = navigator.language.toLowerCase()
    if (browserLang.includes('zh')) return 'zh'
    if (browserLang.includes('ru')) return 'ru'
  }
  return 'en' // 默认英语
}

export default defineNuxtPlugin(({ vueApp }) => {
  const i18n = createI18n({
    legacy: false,
    locale: 'zh',
    fallbackLocale: 'zh',
    messages: {
      zh,
      en,
      ru
    }
  })

  vueApp.use(i18n)
}) 